﻿using CommunityToolkit.Mvvm.Messaging;
using SuperMicroWave.LogFile;
using SuperMicroWave.Messages;
using SuperMicroWave.ViewModels;
using System.Windows;

namespace SuperMicroWave.Dialogs
{
    /// <summary>
    /// InflatingDlg.xaml 的交互逻辑
    /// </summary>
    public partial class InflatingDlg : Window
    {
        public InflatingDlg()
        {
            InitializeComponent();
            DataContext = new InflatingViewModel();

            WeakReferenceMessenger.Default.Register<CloseWindowMessage>(this, (_, m) =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    WeakReferenceMessenger.Default.Unregister<CloseWindowMessage>(this);
                    this.DialogResult = true;
                });
            });
        }

        private void CloseWindowButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("预加压中，是否退出？", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
            if (result == MessageBoxResult.OK)
            {
                LogHelper.WriteInfoLog("退出预加压");
                WeakReferenceMessenger.Default.Unregister<CloseWindowMessage>(this);
                this.DialogResult = false;
            }       
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            LogHelper.WriteInfoLog("预加压：忽略漏气提示，开始升温");
            WeakReferenceMessenger.Default.Unregister<CloseWindowMessage>(this);
            DialogResult = true;
        }
    }
}
